package router

import (
	"go-web/controllers"
	"go-web/exception"
	"go-web/pkg/logger"

	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {
	r := gin.Default()

	// 应用全局异常处理器
	r.Use(exception.GlobalExceptionHandler())
	r.Use(gin.LoggerWithConfig(logger.LoggerToFile()))
	r.Use(logger.Recover)

	user := r.Group("/user")
	{
		user.POST("/login", controllers.UserController{}.Login)
		user.GET("/info/:id", controllers.UserController{}.UserInfo)
		user.GET("/list", controllers.UserController{}.UserList)
		user.GET("/error", controllers.UserController{}.UserError)
	}
	return r
}
